package WordHandling;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.util.ArrayList;
import java.util.Random;

/**One Text object is created for each queried word. Each has unique color and position
 * */
public class Text {
	/**angle (in radians) from zero at which this text was drawn*/
	private double angle;
	/**x coordinate at which this text was drawn in the frame*/
	private int x_coord;
	/**y coordinate at which this text was drawn in the frame*/
	private int y_coord;
	/**Query keyword that this object displays*/
	private String key;
	/**Color for this text*/
	private Color color;
	/**background for the text (so lines are not drawn through it)*/
	private Shape rectangle;
	/**Contains all lines that are drawn from this text to a cluster*/
	private ArrayList<Line> lines = new ArrayList<Line>();
	/**contains all clusters to which lines are drawn from this text*/
	private ArrayList<File_Cluster> clusters = new ArrayList<File_Cluster>();
	/**Graphics object that draws the text*/
	 Graphics2D graph_obj;
	
	Text(Graphics g, int x, int y, String k,double a){
	angle=a;
	x_coord=x;
	y_coord=y;
	key=k;
	graph_obj = (Graphics2D) g;

	
	Random r = new Random();
	 color = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));
	}

	
	/**Draws the Text object and its rectangular background*/
	public void draw_Text(){
		//size of background is based on the length of the keyword
		int background_size = 5;
			for(int i=0; i<key.length();i++){
				background_size+=5;
			}
		
		   graph_obj.setColor(Color.white);
		   rectangle = new Rectangle(x_coord, y_coord-10, background_size, 10);
		   graph_obj.draw(rectangle);
		   graph_obj.fill(rectangle);

		   
		   graph_obj.setPaint(color);
		   Font f = new Font ("Sanserif", Font.BOLD, 12);
		   graph_obj.setFont (f);
		   graph_obj.drawString(key,x_coord,y_coord);
	}
	
	/**adds a line to the lines array for this text object
	 * @param l a line to add to <code>lines</code>*/
	public void addLine(Line l){
		lines.add(l);
	}
	/**adds a cluster to the clusters array for this text object
	 * @param f a cluster to add to <code>clusters</code>*/
	public void addCluster(File_Cluster f){
		clusters.add(f);
	}
	/**@return the list of lines associated with this text object*/
	public ArrayList<Line> getLines(){return lines;}
	/**@return the list of clusters associated with this text object*/
	public ArrayList<File_Cluster> getClusters(){return clusters;}
	/**@return the x coordinate of the position of this text object on its frame*/
	public int getX(){return x_coord;}
	/**@return the y coordinate of the position of this text object on its frame*/
	public int getY(){return y_coord;}
	/**@return the color of this text object*/
	public Color getColor(){return color;}
	/**@return the query keyword that this text object represents*/
	public String getKey(){return key;}
	/**@return the degree (in radians from 0) at which this text object was arranged on the frame*/
	public double getAngle(){return angle;}
	/**@return the background of the text*/
	public Shape getRec(){return rectangle;}
	
}
